package com.assignwork.modules.pc;

import com.assignwork.dto.pcplan.PcShipInfoEnteringSearchDto;
import com.assignwork.dto.pcplan.PcShipInfoEnteringSubmitDto;
import com.assignwork.entity.pc.PcShipInfoEntering;
import com.assignwork.modules.pc.service.pc.IPcShipInfoEnteringService;
import com.assignwork.vo.pc.PcShipInfoEnteringVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @ClassName PcShipInfoEnteringController
 * @Description
 * @Author sl
 * @Date 2023/10/16 9:44
 */
@RestController
@RequestMapping("pcShipInfoEntering")
@AllArgsConstructor
@Api(value = "泊位船时效率", tags = "泊位船时效率")
public class PcShipInfoEnteringController extends BladeController {
    private IPcShipInfoEnteringService service;

    @GetMapping("/page")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "分页", notes = "传入dto")
    public R<IPage<PcShipInfoEnteringVo>> selectPcShipInfoEnteringPage(PcShipInfoEnteringSearchDto dto, Query query) {
        IPage<PcShipInfoEnteringVo> data = service.selectPcShipInfoEnteringPage(dto, Condition.getPage(query));
        return R.data(data);
    }

    @GetMapping("/list")
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "列表", notes = "传入searchDto")
    public R<List<PcShipInfoEnteringVo>> list(PcShipInfoEnteringSearchDto dto) {
        return R.data(service.selectPcShipInfoEnteringList(dto));
    }


    @PostMapping("/submit")
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "新增或修改", notes = "传入entity")
    public R<Boolean> submitPcShipInfoEntering(@Valid @RequestBody PcShipInfoEnteringSubmitDto submitDTO) {
        return R.status(service.submitPcShipInfoEntering(submitDTO));
    }

    @PostMapping("/remove")
    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "删除", notes = "传入id")
    public R<Boolean> remove(@ApiParam(value = "主键集合", required = true) @RequestParam String id) {
        return R.status(service.removePcShipInfoEntering(id));
//        return R.status(service.deleteLogic(Func.toLongList(id)));
    }

    @PostMapping("/finish")
    @ApiOperationSupport(order = 7)
    @ApiOperation(value = "完结", notes = "传入id")
    public R<Boolean> finish(@ApiParam(value = "主键集合", required = true) @RequestParam String id) {
        boolean update = service.update(Wrappers.<PcShipInfoEntering>update().lambda()
                .eq(PcShipInfoEntering::getId, Long.valueOf(id))
                .set(PcShipInfoEntering::getStatus, 2));
        return R.status(update);
    }

    @PostMapping("/recover")
    @ApiOperationSupport(order = 7)
    @ApiOperation(value = "完结", notes = "传入id")
    public R<Boolean> recover(@ApiParam(value = "主键集合", required = true) @RequestParam String id) {
        boolean update = service.update(Wrappers.<PcShipInfoEntering>update().lambda()
                .eq(PcShipInfoEntering::getId, Long.valueOf(id))
                .set(PcShipInfoEntering::getStatus, 1));
        return R.status(update);
    }
}
